%{
  #include <stdlib.h>
  #include <string.h>
  #include "y.tab.h"
%}

identifier [a-zA-Z_]+[0-9a-zA-Z_]*
number     [0-9]|([1-9][0-9]*)

%%

"if"         		{ return IF; }
"while"      		{ return WHILE; }
"done"       		{ return DONE; }
"do"         		{ return DO; }
"then"       		{ return THEN; }
"else"       		{ return ELSE; }
"endif"      		{ return ENDIF; }
"for"        		{ return FOR; }
"to"         		{ return TO; }
"step"       		{ return STEP; }
"true"       		{ return TRUE; }
"false"      		{ return FALSE; }
"int"      		{ return INT; }
"const"      		{ return CONST; }
"main()"      		{ return MAIN; }
"print_d"		{ return PRINTD; }
"print_s"		{ return PRINTS; }
"stencil"		{ return STENCIL; }
"return"      		{ return RETURN; }
"abs"      		{ return ABS; }
\"([^\\\"]|\\.)*\"      { yylval.string = strdup(yytext);return STRING; }
{identifier} 		{ yylval.string = strdup(yytext); return ID; }
{number}     		{ yylval.value = atoi(yytext); return NUM; }
"=="         		{ return EQUAL; }
"!="         		{ return DIFF; }
"<"         		{ return INF; }
"<="         		{ return INF_EQUAL; }
">"         		{ return SUP; }
">="         		{ return SUP_EQUAL; }
[=]          		{ return ASSIGN; }
"&&"         		{ return AND; }
"||"         		{ return OR; }
"!"          		{ return NOT; }
"++"          		{ return PLUS_PLUS; }
"--"          		{ return MOINS_MOINS; }
[(+\-\*/{}();\[\],]         	{ return yytext[0]; }
[\t \n]        		{ }
.            		{ printf("[Lex] Unknown character: %s\n", yytext); }

%%

// Free the memory allocated for Lex when we are done.
void lex_free() {
  yy_delete_buffer(YY_CURRENT_BUFFER);
  free(yy_buffer_stack);
}
